﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineCooperation.Entity;
using OnlineCooperation.DB;
using OnlineCooperation.AppCode;

namespace OnlineCooperation
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonRegisterClick(object sender, EventArgs e)
        {
            string email = SetEmail.Value;
            string name = SetUserName.Value;

            if (name == "")
            {
                Response.Write("<script>alert('用户名不能为空！')</script>");
                return;
            }

            if (!MyValidate.IsEmail(email))
            {
                Response.Write("<script>alert('无效的邮箱')</script>");
                return;
            }

            string pwd = SetPwd.Value;
            string pwd2=ConfirmPwd.Value;

            if (pwd.Length < 6)
            {
                Response.Write("<script>alert('请输入足够长的密码！')</script>");
                return;
            }


            if (pwd != pwd2)
            {
                Response.Write("<script>alert('两次输入密码不一致！')</script>");
                return;
            }

            UserDB ud = new UserDB();
            User u = new User(0, name, email, pwd, "/AppData/DefaultIcon/Icon_male.jpg");

            int code=ud.Insert(u);

            switch (code)
            {
                case 0:
                    Response.Write("<script>alert('该邮箱已注册')</script>");
                    break;
                case -1:
                    Response.Write("<script>alert('该用户名已注册')</script>");
                    break;
                default:
                    Session["UserEmail"] = email;
                    Session["UserPwd"] = pwd;


                    Response.Redirect("Login.aspx");
                    break;
            }
        }

        protected void ButtonSetupTeamClick(object sender, EventArgs e)
        {

        }
    }
}